﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Systematize.Domain.Data;
using Systematize.Domain.Entities;

namespace Systematize.Domain.Services
{
    public class LibraryItemService<T> : ILibraryItemService<T>
        where T : EditableEntity
    {
        private readonly IRepository<T> _repository;

        public LibraryItemService(IRepository<T> repository)
        {
            _repository = repository;
        }

        public void Update(T entity)
        {
            entity.ModifiedOn = DateTime.Now;
            _repository.Update(entity);
        }

        public void Create(T entity)
        {
            _repository.Insert(entity);
        }

        public int Count()
        {
            return _repository.Count();
        }

        public int Count(Expression<Func<T, bool>> predicate)
        {
            return _repository.Count(predicate);
        }

        public T GetById(int id)
        {
            return _repository.Find(i => i.Id == id);
        }

        public IEnumerable<T> GetAll()
        {
            return _repository.GetAll();
        }

        public T Find(Expression<Func<T, bool>> predicate)
        {
            return _repository.Find(predicate);
        }

        public IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate)
        {
            return _repository.FindAll(predicate);
        }
    }
}
